using System;
using System.Collections;
using System.Collections.Generic;
using MyFrame.Event;
using MyFrame.Mono;
using MyFrame.Single;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;


namespace MyFrame.Scenen
{
    public class SceneMgr : Singleton<SceneMgr>
    {

        public void LoadScene(string sceneName, UnityAction fun)
        {
            SceneManager.LoadScene(sceneName);
            fun();
        }

        public void LoadSceneAsync(string sceneName, UnityAction fun)
        {
            MonoMgr.Instance.StartCoroutine(ReallyLoadSceneAsync(sceneName, fun));
        }
        private IEnumerator ReallyLoadSceneAsync(string sceneName, UnityAction fun)
        {
            AsyncOperation ao = SceneManager.LoadSceneAsync(sceneName);
            // 获取进度
            while (!ao.isDone)
            {
                EventCenter.Instance.Emit<float>(EventEnum.LoadSceneProgress, ao.progress);
                yield return ao.progress;
            }
            fun();
        }
    }

}
